﻿Imports System.Data
Imports System.Data.SqlClient

Public Class Autent

    Dim password As String
    Dim cargo As String


    Private Sub button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button1.Click

        Try
            Dim strCon As String = "Data Source=(local)\SQLEXPRESS ;Initial Catalog=cegan ;Integrated Security=True"
            Dim sql As String = "select pass,area from trabajador where rut_trabajador='" & textBox1.Text & "';"
            Dim tabla As New DataTable
            Dim adaptador As New SqlDataAdapter(sql, strCon)
            adaptador.Fill(tabla)

            password = tabla.Rows(0)("pass")
            cargo = tabla.Rows(0)("area")

        Catch ex As Exception
            MsgBox("Usuario no registrado", MsgBoxStyle.Critical, "Error")
            GoTo salto
        End Try

        If cargo = area Or cargo = root Then

            If password = textBox2.Text Then

                If area = "ADMINISTRATIVO" Then
                    Proyectos.Show()
                End If
                If area = "RRHH" Then
                    RecursosHumanos.Show()
                End If
                If area = "ADMINISTRATIVO TECNICO" Then
                    Materiales.Show()
                End If
                If area = "FINANZAS" Then
                    Finanzas.Show()
                End If

                Main.WindowState = FormWindowState.Minimized
                Me.Close()


            Else
                MsgBox("Contraseña incorrecta", MsgBoxStyle.Information, "Error")
            End If
        ElseIf cargo = vbNull Then
            MsgBox("Usuario sin privilegios para esta zona", MsgBoxStyle.Information, "Error")

        End If
salto:
    End Sub

    

    Private Sub textBox2_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles textBox2.KeyPress
        If e.KeyChar = Convert.ToChar(Keys.Return) Then
            Me.button1.PerformClick()
            e.Handled = True
        End If
    End Sub

    

    
    Private Sub button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button2.Click
        Autent2.ShowDialog()
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Autent3.ShowDialog()
    End Sub
End Class